$(document).ready(function() {
		// alert(getCookie('product_order'))
		var sorce = decodeURIComponent((new RegExp('[?|&]sorce=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
		var productid = decodeURIComponent((new RegExp('[?|&]product_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
		var lucky_record_id = decodeURIComponent((new RegExp('[?|&]lucky_record_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
		var datac = decodeURIComponent((new RegExp('[?|&]datac=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
		

	if (getCookie('product_order')) {
		var url_pro = JSON.parse(getCookie('product_order'));
	}
	
	
	// var attr_id = url_pro.attr_id
	// var num = url_pro.num
	
	// var product_id = decodeURIComponent((new RegExp('[?|&]product_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// var attr_id = decodeURIComponent((new RegExp('[?|&]attr_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	// var num = decodeURIComponent((new RegExp('[?|&]num=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
	$('.checkbox').click(function(event) {
		

		var address_id = $(this).attr('data-address-id')


		
		if (sorce == 4) {
			window.location.href = localhosthref+"?product_id="+productid+"&lucky_record_id="+lucky_record_id+"&sorce="+sorce+"&datac="+datac + '&address_id=' + address_id
		} else {
			
			var action = decodeURIComponent((new RegExp('[?|&]action=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
			
			// var lucky_record_id = decodeURIComponent((new RegExp('[?|&]lucky_record_id=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
			// var sorce = decodeURIComponent((new RegExp('[?|&]sorce=' + '([^&;]+?)(&|#|;|$)', "ig").exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
			
			var product_id = url_pro.product_id
			SetCookie('select_address', address_id)
			// window.location.href = urls + '?product_id=' + product_id + '&attr_id=' + attr_id + '&num=' + num + '&address_id=' + address_id
			window.location.href = urls + '?product_id=' + product_id + '&address_id=' + address_id
		}
	});
//	编辑地址
	$('.address_div li').click(function(){
		var dom = $(this).find("a")
		var datahref = dom.attr('data-href')+"&sorce="+sorce+"&product_id="+productid+"&lucky_record_id="+lucky_record_id+"&datac="+datac
		dom.attr("href",datahref)
		
	})
	
	$('.btn').click(function() {
		var addressid = $(this).parent().attr('data-addressid')
		console.log(addressid)
		$.ajax({
			url: del,
			type: 'post',
			data: {
				address_id: addressid
			},
			success: function(data) {
				window.location.reload();
			},
			error:function(xhr, textStatus){
				if(xhr.status == 401){
					 window.location.href = "/Npoint_store/Login";
				}else{
					alert('系统错误')
				}

			}
		})
	});
	
//	新增地址
	

		

		$('.addnew_address').click(function(event) {
			// window.location.href = address_detail_urls + '?product_id=' + product_id + '&attr_id=' + attr_id + '&num=' + num
//			奖品新增地址
			if(sorce == 4){
				window.location.href = address_detail_urls + '?product_id=' + productid + '&sorce=' + sorce + '&lucky_record_id=' + lucky_record_id + '&datac=' + datac
			}else{
//				兑换新增地址
				window.location.href = address_detail_urls
			}
			var arr = {}
			arr.p = 1
			arr.c = 1
			arr.pid = 1
	//		arr.cid = $(this).find('.address').attr('data-cid')
			var Provinces = JSON.stringify(arr);
			SetCookie('Provinces',Provinces )
		});
	
	
	
	
	$('.con').click(function(event) {
		var arr ={}
		arr.p = $(this).find('.address').attr('data-p')
		arr.c = $(this).find('.address').attr('data-c')
		arr.pid = $(this).find('.address').attr('data-pid')
		arr.cid = $(this).find('.address').attr('data-cid')
		var Provinces = JSON.stringify(arr);
		SetCookie('Provinces',Provinces )

		
	});
});

